home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWDrgDrp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  13.5 KB  |  506 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDrgDrp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWDRGDRP_H
  13. #include "FWDrgDrp.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWKIND_H
  21. #include "FWKind.h"
  22. #endif
  23.  
  24. #ifndef FWFRAME_H
  25. #include "FWFrame.h"
  26. #endif
  27.  
  28. #ifndef FWSELECT_H
  29. #include "FWSelect.h"
  30. #endif
  31.  
  32. #ifndef FWDRCMD_H
  33. #include "FWDrCmd.h"
  34. #endif
  35.  
  36. #ifndef FWTRACKR_H
  37. #include "FWTrackr.h"
  38. #endif
  39.  
  40. #ifndef FWUTIL_H
  41. #include "FWUtil.h"
  42. #endif
  43.  
  44. #ifndef FWCONTXT_H
  45. #include "FWContxt.h"
  46. #endif
  47.  
  48. #ifndef FWPRESEN_H
  49. #include "FWPresen.h"
  50. #endif
  51.  
  52. #ifndef FWPRTITE_H
  53. #include "FWPrtIte.h"
  54. #endif
  55.  
  56. #ifndef FWSESION_H
  57. #include "FWSesion.h"
  58. #endif
  59.  
  60. // ----- OS Includes -----
  61.  
  62. #ifndef FWEVENT_H
  63. #include "FWEvent.h"
  64. #endif
  65.  
  66. #ifndef FWBARRAY_H
  67. #include "FWBArray.h"
  68. #endif
  69.  
  70. #ifndef FWACQUIR_H
  71. #include "FWAcquir.h"
  72. #endif
  73.  
  74. // ----- Foundation Includes -----
  75.  
  76. #ifndef FWMEMMGR_H
  77. #include "FWMemMgr.h"
  78. #endif
  79.  
  80. #ifndef FWDEBUG_H
  81. #include "FWDebug.h"
  82. #endif
  83.  
  84. // ----- OpenDoc Includes -----
  85.  
  86. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  87. #include <StdDefs.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODDragAndDrop_xh
  91. #include <DragDrp.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODDragItemIterator_xh
  95. #include <DgItmIt.xh>
  96. #endif
  97.  
  98. #ifndef SOM_ODSession_xh
  99. #include <ODSessn.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODTranslation_xh
  103. #include <Translt.xh>
  104. #endif
  105.  
  106. #ifndef SOM_ODTransform_xh
  107. #include <Trnsform.xh>
  108. #endif
  109.  
  110. #ifndef SOM_Module_OpenDoc_StdProps_defined
  111. #include <StdProps.xh>
  112. #endif
  113.  
  114. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  115. #include <StdTypes.xh>
  116. #endif
  117.  
  118. // ----- Macintosh Includes -----
  119.  
  120. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  121. #include <Drag.h>
  122. #endif
  123.  
  124. //========================================================================================
  125. //    RunTime Info
  126. //========================================================================================
  127.  
  128. #ifdef FW_BUILD_MAC
  129. #pragma segment FWFrameworkCommands
  130. #endif
  131.  
  132. //========================================================================================
  133. //    class FW_MDraggableFrame
  134. //========================================================================================
  135.  
  136. FW_DEFINE_CLASS_M0(FW_MDraggableFrame)
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    FW_MDraggableFrame::FW_MDraggableFrame
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_MDraggableFrame::FW_MDraggableFrame(Environment *ev, FW_CFrame* frame) :
  143.     fPart(frame->GetPart(ev)),
  144.     fFrame(frame)
  145. {
  146.     fFrame->PrivSetDraggable(ev, this);
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    FW_MDraggableFrame::~FW_MDraggableFrame
  151. //----------------------------------------------------------------------------------------
  152.  
  153. FW_MDraggableFrame::~FW_MDraggableFrame()
  154. {
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    FW_MDraggableFrame::Drag
  159. //----------------------------------------------------------------------------------------
  160.  
  161. FW_Boolean FW_MDraggableFrame::Drag(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  162. {
  163.     if (!theMouseEvent.WaitUntilMouseMoved(ev))
  164.         return FALSE;
  165.  
  166. #ifdef FW_DEBUG    
  167.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, theMouseEvent.GetFacet(ev)->GetFrame(ev));
  168.     FW_ASSERT(frame == fFrame);
  169. #endif    
  170.  
  171.     FW_CDragCommand* dragCommand = this->NewDragCommand(ev, fFrame, theMouseEvent);
  172.     if (dragCommand)
  173.     {
  174.         FW_CPresentation* presentation = fFrame->GetPresentation(ev);
  175.         presentation->PrivSetDragPending(TRUE);
  176.  
  177.         short level = 0;
  178.         FW_VOLATILE(level);
  179.         
  180.         FW_TRY
  181.         {
  182.             dragCommand->BeginDrag(ev, theMouseEvent);
  183.             level = 1;
  184.             dragCommand->Execute(ev);
  185.         }
  186.         FW_CATCH_BEGIN
  187.         FW_CATCH_EVERYTHING()
  188.         {
  189.             if (level == 0)        // throw in BeginDrag
  190.                 delete dragCommand;
  191.                 
  192.             presentation->PrivSetDragPending(FALSE);
  193.             
  194.             FW_THROW_SAME();
  195.         }
  196.         FW_CATCH_END
  197.         
  198.         presentation->PrivSetDragPending(FALSE);
  199.  
  200.         return TRUE;
  201.     }
  202.  
  203.     return FALSE;
  204. }
  205.  
  206. //========================================================================================
  207. //    class FW_MDroppableFrame
  208. //========================================================================================
  209.  
  210. FW_DEFINE_CLASS_M0(FW_MDroppableFrame)
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    FW_MDroppableFrame::FW_MDroppableFrame
  214. //----------------------------------------------------------------------------------------
  215.  
  216. FW_MDroppableFrame::FW_MDroppableFrame(Environment *ev, FW_CFrame* frame) :
  217.     fPart(frame->GetPart(ev)),
  218.     fFrame(frame),
  219.     fCursorInContent(FALSE),
  220.     fCanAcceptDrop(FALSE),
  221.     fDropTracker(NULL)
  222. {
  223.     FW_ASSERT(fFrame);
  224.     
  225.     fFrame->PrivSetDroppable(ev, this, PrivIsDroppable(ev));
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    FW_MDroppableFrame::~FW_MDroppableFrame
  230. //----------------------------------------------------------------------------------------
  231.  
  232. FW_MDroppableFrame::~FW_MDroppableFrame()
  233. {
  234.     delete    fDropTracker;
  235.     fDropTracker = NULL;
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. //    FW_MDroppableFrame::GetCanAcceptDrop
  240. //----------------------------------------------------------------------------------------
  241.  
  242. FW_Boolean FW_MDroppableFrame::GetCanAcceptDrop(Environment* ev) const
  243. {
  244. FW_UNUSED(ev);
  245.  
  246.     return fCanAcceptDrop && PrivIsDroppable(ev);
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. //    FW_MDroppableFrame::GetDropTracker
  251. //----------------------------------------------------------------------------------------
  252.  
  253. FW_CDropTracker* FW_MDroppableFrame::GetDropTracker(Environment* ev) const
  254. {
  255. FW_UNUSED(ev);
  256.     return fDropTracker;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_MDroppableFrame::ChangeDroppableState
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void FW_MDroppableFrame::ChangeDroppableState(Environment* ev, FW_DroppableState droppable)
  264. {
  265.     fFrame->PrivSetDroppableState(droppable);
  266.     fFrame->PrivSetDroppable(ev, this, PrivIsDroppable(ev));
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. //    FW_MDroppableFrame::CanAcceptDrop
  271. //----------------------------------------------------------------------------------------
  272.  
  273. ODDragResult FW_MDroppableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  274. {
  275.     ODDragResult canAcceptDrop = TRUE;
  276.     FW_Boolean atLeastOneSU = FALSE;
  277.     
  278.     for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  279.     {
  280.         atLeastOneSU = TRUE;
  281.         // if can't accept one of the item refuse the drop
  282.         if (fPart->GetSupportedKind(ev, dragSU, FW_kDragAndDropStorage) == NULL)
  283.         {
  284.             canAcceptDrop = FALSE;
  285.             break;
  286.         }
  287.     }
  288.     
  289.     return canAcceptDrop && atLeastOneSU;
  290. }
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    FW_MDroppableFrame::DragEnter
  294. //----------------------------------------------------------------------------------------
  295. // 'where' is in frame coordinate
  296.  
  297. ODDragResult FW_MDroppableFrame::DragEnter(Environment *ev, 
  298.                                             ODFacet* facet, 
  299.                                             ODDragItemIterator* dragInfo, 
  300.                                             const FW_CPoint& where)
  301. {    
  302. FW_UNUSED(where);
  303.  
  304.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  305.     FW_ASSERT(frame != NULL);
  306.  
  307.     if (fPart->IsReadOnly(ev) || !PrivIsDroppable(ev))
  308.         fCanAcceptDrop = FALSE;
  309.     else 
  310.         fCanAcceptDrop = CanAcceptDrop(ev, dragInfo);
  311.     
  312.     FW_CSuperView* contentView = frame->GetContentView(ev);
  313.     FW_ASSERT(contentView != NULL);
  314.     
  315.     fDropTracker = NewDropTracker(ev, contentView, facet);
  316.     
  317.     fCursorInContent = FALSE;
  318.         
  319.     return fCanAcceptDrop;
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    FW_MDroppableFrame::DragWithin
  324. //----------------------------------------------------------------------------------------
  325. // 'where' is in frame coordinate
  326.  
  327. ODDragResult FW_MDroppableFrame::DragWithin(Environment* ev, 
  328.                                             ODFacet* facet, 
  329.                                             ODDragItemIterator* dragInfo, 
  330.                                             const FW_CPoint& where)
  331. {
  332.     FW_UNUSED(dragInfo);
  333.  
  334.     if (!fCanAcceptDrop)
  335.         return FALSE;
  336.         
  337. // [HLX] OpenDoc Bug Begin
  338. //    OpenDoc sometimes call DragWithin without calling DragEnter
  339.     if (fDropTracker == NULL && !DragEnter(ev, facet, dragInfo, where))
  340.         return FALSE;
  341. //     [HLX] OpenDoc Bug End    
  342.  
  343.     unsigned long attributes = FW_CSession::GetDragAndDrop(ev)->GetDragAttributes(ev);
  344.  
  345.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  346.     FW_ASSERT(frame != NULL);
  347.  
  348.     FW_CView* contentView = frame->GetContentView(ev);
  349.     
  350.     FW_Boolean cursorInContent = contentView->IsMouseWithin(ev, facet, where);
  351.     
  352.     if (cursorInContent)
  353.     {
  354.         if (!fCursorInContent)
  355.             fDropTracker->HandleBeginTracking(ev, where, attributes);
  356.     }
  357.     else
  358.     {
  359.         if (fCursorInContent)
  360.             fDropTracker->HandleEndTracking(ev, where);
  361.     }
  362.     
  363.     fCursorInContent = cursorInContent;
  364.     
  365.     if (fCursorInContent)
  366.         fDropTracker->HandleContinueTracking(ev, where);
  367.     
  368.     return TRUE;
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. //    FW_MDroppableFrame::DragLeave
  373. //----------------------------------------------------------------------------------------
  374. // 'where' is in frame coordinate
  375.  
  376. void FW_MDroppableFrame::DragLeave(Environment *ev, ODFacet* facet, const FW_CPoint& where)
  377. {
  378. FW_UNUSED(facet);
  379.     if (!fCanAcceptDrop)
  380.         return;
  381.     
  382.     FW_ASSERT(fDropTracker);
  383.     
  384.     if (fCursorInContent)    
  385.         fDropTracker->HandleEndTracking(ev, where);
  386.     
  387.     fCursorInContent = FALSE;
  388.     
  389.     // If there was a tracker delete it
  390.     delete fDropTracker;        
  391.     fDropTracker = NULL;
  392. }
  393.  
  394. //----------------------------------------------------------------------------------------
  395. //    FW_MDroppableFrame::AcquireDragHiliteShape
  396. //----------------------------------------------------------------------------------------
  397.  
  398. ODShape* FW_MDroppableFrame::AcquireDragHiliteShape(Environment* ev, ODFacet* facet)
  399. {
  400. FW_UNUSED(facet);
  401.  
  402.     FW_ASSERT(fFrame->GetODFrame(ev) == facet->GetFrame(ev));
  403.     FW_CAcquiredODShape contentShape = fFrame->AcquireContentShape(ev);
  404.     return contentShape->Copy(ev);
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. //    FW_MDroppableFrame::Drop    
  409. //----------------------------------------------------------------------------------------
  410.  
  411. FW_DECLARE_THROW_POINT (FW_MDroppableFrame_Drop_BeforePerform);
  412.  
  413. ODDropResult FW_MDroppableFrame::Drop(Environment *ev, ODDragItemIterator* dropInfo,
  414.                                     ODFacet* facet, const FW_CPoint& where)    // in frame coordinate
  415. {
  416.  
  417.     ODDropResult dropResult = kODDropFail;
  418.  
  419.     if (fCursorInContent)
  420.     {
  421.         FW_ASSERT(fDropTracker);
  422.         fDropTracker->HandleEndTracking(ev, where);
  423.     }
  424.     
  425.     delete fDropTracker;    
  426.     fDropTracker = NULL;
  427.  
  428.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  429.     FW_ASSERT(frame != NULL);
  430.                 
  431.     if (!fPart->IsReadOnly(ev) && fCursorInContent)
  432.     {    
  433.         // ----- 'where' is in frame coordinate. Put it in content coordinate
  434.         FW_CPoint dropPoint(where);
  435.         FW_FrameToContent(ev, frame->GetODFrame(ev), dropPoint);
  436.         
  437.         FW_CDropCommand* dropCommand = this->NewDropCommand(ev, frame, dropInfo, facet, dropPoint);
  438.         
  439.         if (dropCommand)
  440.         {
  441.             FW_Boolean undoable = dropCommand->Execute(ev, FALSE);    // do not delete if not undoable        
  442.             
  443.             dropResult = dropCommand->GetDropResult(ev);
  444.             
  445.             if (!undoable)
  446.                 delete dropCommand;
  447.         }
  448.     }
  449.     
  450.     // ----- Always activate the frame at the end -----
  451.     frame->ActivateWindow(ev, facet, TRUE);
  452.     
  453.     return dropResult;
  454. }
  455.  
  456. //----------------------------------------------------------------------------------------
  457. //    FW_MDroppableFrame::NewDropTracker
  458. //----------------------------------------------------------------------------------------
  459.  
  460. FW_CDropTracker* FW_MDroppableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
  461. {
  462.     return new FW_CDropTracker(ev, view, facet);
  463. }
  464.  
  465. //----------------------------------------------------------------------------------------
  466. //    FW_MDroppableFrame::GetDroppableState
  467. //----------------------------------------------------------------------------------------
  468.  
  469. FW_DroppableState FW_MDroppableFrame::GetDroppableState(Environment* ev) const
  470. {
  471. FW_UNUSED(ev);
  472.  
  473.     return fFrame->PrivGetDroppableState();
  474. }
  475.  
  476. //----------------------------------------------------------------------------------------
  477. //    FW_MDroppableFrame::PrivIsDroppable
  478. //----------------------------------------------------------------------------------------
  479.  
  480. FW_Boolean FW_MDroppableFrame::PrivIsDroppable(Environment *ev) const
  481. {
  482.     return FW_MDroppableFrame::PrivDroppableStateToBoolean(fFrame->PrivGetDroppableState(), fFrame->GetViewType(ev));
  483. }
  484.  
  485. //----------------------------------------------------------------------------------------
  486. //    FW_MDroppableFrame::PrivDroppableStateToBoolean
  487. //----------------------------------------------------------------------------------------
  488.  
  489. FW_Boolean FW_MDroppableFrame::PrivDroppableStateToBoolean(FW_DroppableState droppable, ODTypeToken viewType)
  490. {
  491.     if (droppable == FW_kNotDroppable)
  492.         return FALSE;
  493.     else if (((droppable & FW_kFrameDroppable) != 0)  && (viewType == FW_CPart::fgViewAsFrameToken))
  494.         return TRUE;
  495.     else if (((droppable & FW_kThumbnailDroppable) != 0)  && (viewType == FW_CPart::fgViewAsThumbnailToken))
  496.         return TRUE;
  497.     else if (((droppable & FW_kIconDroppable) != 0)  && (viewType == FW_CPart::fgViewAsSmallIconToken || viewType == FW_CPart::fgViewAsLargeIconToken))
  498.         return TRUE;
  499.     
  500.     return FALSE;
  501. }
  502.  
  503.  
  504.  
  505.  
  506.